package com.jdk.learn.gui;

import javax.swing.*;
import java.awt.*;

/**
 * Created by baiguantao on 2018/1/18.
 */
public class JAVAGUI {
    JFrame frame=new JFrame("JComboBoxDemo");
    JComboBox<String> jcb1,jcb2;
    JTextArea ta=new JTextArea(0,30);



    public  void go(){
        JPanel p1=new JPanel();
        JPanel p2=new JPanel();
        JPanel p3=new JPanel();
        JPanel p4=new JPanel();

        String[] itemList={"1","1","3","1","1","6"};

        jcb1=new JComboBox<String>(itemList);

        p1.add(jcb1);

        jcb1.setSelectedIndex(2);

        p4.setLayout(new GridLayout(0,1));
        p4.add(p1);
        Container cp=frame.getContentPane();
        cp.setLayout(new GridLayout(0,1));

        cp.add(p4);

        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * p216
     * 文本区对象置于滚动面板
     */
    public void JtextAreaOnJscroll(){
        JFrame f=new JFrame("文本区TO滚动面板");

        JTextArea ta=new JTextArea(4,5);//4行五列
        ta.setLineWrap(true);//自动换行
        ta.append("默认内容");
        JScrollPane jsp=new JScrollPane(ta);
        jsp.setSize(100,100);
        f.getContentPane().add(jsp);
        GuiUtils.JframeInit(f);

    }

    /**
     * p216
     * 面板类似登录对话框
     */
    public void p216_twologin(){
        JFrame f=new JFrame("My Frame");


        JPanel workp=new JPanel();
        workp.setSize(200,200);
        workp.setPreferredSize(new Dimension(100,100));
        workp.setLayout(new GridLayout(3,1));


        JLabel source=new JLabel("source");
        JLabel target=new JLabel("target");


        workp.add(source);
        JTextField sourcetxt=new JTextField();
        workp.add(sourcetxt);


        workp.add(target);

        JTextField targettxt=new JTextField();
        workp.add(targettxt);

        f.getContentPane().add(workp);
        GuiUtils.JframeInit(f);

    }

    public void paintComponent(Graphics g){
//        g.drawImage()

    }
    public static void main(String[] args) {
        JAVAGUI jd=new JAVAGUI();

        Toolkit tool=Toolkit.getDefaultToolkit();

        jd.p216_twologin();
    }

}
